#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int const maxn = 402;
int const maxa = 40002;
bool f[maxn][maxa];

struct data { int h, a, c; };
struct cmp { bool operator()(data a, data b) { return a.a < b.a; } }cmp;
int n;
vector<data> da;

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	da.resize(n);
	for (int i = 0; i < n; i++) cin >> da[i].h >> da[i].a >> da[i].c;
	sort(da.begin(), da.end(), cmp);

	for (int i = 0; i <= da[0].c && i*da[0].h <= da[0].a; i++)
		f[0][i*da[0].h] = true;
	for (int i = 1; i < n; i++) {
		for (int j = 0; j <= da[i].a; j++) {
			for (int k = 0; k <= da[i].c && k*da[i].h <= j; k++) {
				if (f[i-1][j-k*da[i].h]) {
					f[i][j] = true;
					break;
				}
			}
		}
	}
	int i = da[n-1].a;
	for (; i >= 0; i--) if (f[n-1][i]) break;
	cout << i << "\n";
}


